($(function() {
	$.ajax({
		type: "get",
		url: "http://leancloud.cn:443/1.1/classes/GoodsDetails",
		headers: {
			"X-LC-Id": "zHIcdwsqTv0sth9xulaRyDUz-gzGzoHsz",
			"X-LC-Key": "tjE4NDCjRHN5PIKF46cHGWqV"
		},
		async: true,
		contentType: "application/json",
		success: function(data) {
			getGoodsInfo(data);
		}

	});
}))();

function getGoodsInfo(data) {
	var TGID = window.location.href.split("?")[1].split("&")[0].split("=")[1]-1;
	console.log(TGID);
	//01
	//01-01 加载  商品详情的大图goodsPicSrc
	var TGDetail_Json = JSON.parse(data.results[TGID].TGDetail);
	var s_img_goodsPicSrc = document.getElementById("s_img_goodsPicSrc");
	s_img_goodsPicSrc.src = TGDetail_Json.goodsPicSrc;
	//01-02 加载 商品详情的标题title 
	var s_goodstitle = document.getElementById("s_goodstitle");
	s_goodstitle.innerHTML = TGDetail_Json.goodsTitl;
	//01-03 加载 商品详情的价格
	var s_shangpin_price = document.getElementById("s_shangpin_price");
	s_shangpin_price.innerHTML = TGDetail_Json.goodsPrice;
	//01-04 加载 月销
	var s_goodsMouthSale = document.getElementById("s_goodsMouthSale");
	s_goodsMouthSale.innerHTML = TGDetail_Json.goodsMonthSales;
	//01-05 加载 礼物寓意
	var s_goodsMoral = document.getElementById("s_goodsMoral");
	s_goodsMoral.innerHTML = TGDetail_Json.goodsMoral;
	//Json物品细节
	//console.log(obj[1].TGDetail);
	//console.log(TGDetail_Json.goodsPicSrc);
	//console.log(typeof TGDetail_Json.goodsPicSrc);

	// 第二层  开始的
	var classes = TGDetail_Json.goodsClass.split(",");
	var class01Arr = classes[0].split("-");
	var class02Arr = classes[1].split("-");
	var class03Arr = classes[2].split("-");
	var class04Arr = classes[3].split("-");
	document.getElementById("classs01").innerHTML = class01Arr[0];
	document.getElementById("classs02").innerHTML = class02Arr[0];
	document.getElementById("classs03").innerHTML = class03Arr[0];
	document.getElementById("classs04").innerHTML = class04Arr[0];
	/**
	 * 第二层数据的加载
	 * 取到我的网络数据之后进行动态的加载
	 * 主要实现     动态数据加载以及功能的实现
	 * */
	$("#kuanshi_choose li a").click(function() {
		var myKuanShi = $(this).get(0).innerHTML;
		//判断实现选择样式的实现
		if(!$("#kuanshi_choose li").hasClass("h_choose")) {
			$(this).parent().addClass("h_choose");
		} else {
			$("#kuanshi_choose li").removeClass("h_choose");
			$(this).parent().addClass("h_choose");
		}
		//此处是进行  选择成功后的选项样式的赋值  以及  数据的加载
		$("#myKuanShi").html(myKuanShi);
		for(var i = 0; i < classes.length; i++) {
			if(myKuanShi == classes[i].split("-")[0]) {
				console.log(classes[i].split("-")[0]);
				$("#s_classPrice").html(classes[i].split("-")[1]);
				$("#s_classNumber").html(classes[i].split("-")[2]);
			}
		}
	});


	//02
	//02-00 加载  详情图片
	console.log(data.results[TGID].TGDetailPic)
	var TGDetailPic_Arr = data.results[TGID].TGDetailPic.split(",");
	var s_goodsXiangQing = document.getElementById("s_goodsXiangQing");
	for(var i = 0; i < TGDetailPic_Arr.length; i++) {
		var tempImg = document.createElement("img");
		tempImg.src = TGDetailPic_Arr[i];
		s_goodsXiangQing.appendChild(tempImg);
	}


	//03
	//03-00 加载 物品的评论信息
	var TGComment_Arr = data.results[TGID].TGComment.split("-");
	var TGComment_Arr_Json = [];
	var s_listComment = document.getElementById("s_listComment");
	var Str = "";
	for(var i = 0; i < TGComment_Arr.length; i++) {
		TGComment_Arr_Json[i] = JSON.parse(TGComment_Arr[i]);
		Str +=
			'<li>' +
			'<span class="pl_touxiang">' +
			'	<img src="' + TGComment_Arr_Json[i].userPic + '" />' +
			'</span>' +
			'<p class="pl_name">' + TGComment_Arr_Json[i].username + '</p>' +
			'<p class="pl_neirong">' + TGComment_Arr_Json[i].contents + '</p>' +
			'</li>';
	}
	s_listComment.innerHTML += Str;

}